package com.ruoyi.web.service.warning.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.web.domain.warning.FactorInfo;
import com.ruoyi.web.mapper.warning.FactorInfoMapper;
import com.ruoyi.web.service.warning.FactorInfoService;
import com.ruoyi.web.utils.v2.V2RremoteCall;
import com.ruoyi.web.utils.wuqing.WQRremoteCall;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 因子管理表 服务实现类
 * @author fwx
 * @date 2024-01-30 15:02:56
 */
@Service
@Slf4j
@DataSource(value = DataSourceType.SLAVE)
public class FactorInfoServiceImpl extends ServiceImpl<FactorInfoMapper, FactorInfo> implements FactorInfoService {

    /**
    * 查询所有因子管理表
    */
    @Override
    public List<FactorInfo> queryAll(){
        return WQRremoteCall.getFactorAll();
    }

    @Override
    public Map<String,FactorInfo> getAllMap(){
        List<FactorInfo> factorInfos = this.queryAll();
        Map<String, FactorInfo> result = factorInfos.stream().collect(Collectors.toMap(FactorInfo::getFactorKey, Function.identity(),(x1,x2) -> x1));
        return result;
    }

    @Override
    public FactorInfo getByProperty(String property,Long productId){
        //查询因子, 判断展示项
        String factorKey = V2RremoteCall.getFactorKey(property, productId);
        Map<String, FactorInfo> fatorMap = this.getAllMap();
        log.info("key: " + factorKey);
        FactorInfo factor = fatorMap.get(factorKey);

        if(factor == null){
            return new FactorInfo();
        }

        return factor;
    }

    @Override
    public List<FactorInfo> getByType(String factorType){
        return WQRremoteCall.getFactorByType(factorType);
    }

}
